<template>
	<view class='content'>
		<view class="titles">可通过以下方式找到我</view>
		<view class="cu-form-group ">
			<view class="title">手机号</view>
			<switch @change="SwitchA" :class="switchA?'checked':''" :checked="switchA?true:false"></switch>
		</view>
		<view class="cu-form-group ">
			<view class="title">ID号</view>
			<switch @change="SwitchB" :class="switchB?'checked':''" :checked="switchB?true:false"></switch>
		</view>
		<view class="titles">可通过以下方式添加我</view>
		<view class="cu-form-group ">
			<view class="title">群聊</view>
			<switch @change="SwitchC" :class="switchC?'checked':''" :checked="switchC?true:false"></switch>
		</view>
		<view class="cu-form-group ">
			<view class="title">二维码</view>
			<switch @change="SwitchD" :class="switchD?'checked':''" :checked="switchD?true:false"></switch>
		</view>
		<view class="cu-form-group ">
			<view class="title">名片</view>
			<switch @change="SwitchE" :class="switchE?'checked':''" :checked="switchE?true:false"></switch>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				switchA: true,
				switchB: true,
				switchC: true,
				switchD: true,
				switchE: true
			}
		},
		onLoad(){
			
		},
		onShow(){
			this.$msgchat.initwork();
			this.initdata();
		},
		methods:{
			initdata(){
				var obj = {
					token: uni.getStorageSync('token')
				}
				this.$common.requests('/api/Group/checkmyvip', obj).then(res => {
					// console.log(res)
					if(res.data.code==1){
						this.switchA = res.data.data.findtype_phone==1?true:false;
						this.switchB = res.data.data.findtype_id==1?true:false;
						this.switchC = res.data.data.addtype_group==1?true:false;
						this.switchD = res.data.data.addtype_code==1?true:false;
						this.switchE = res.data.data.addtype_ming==1?true:false;
					}else{
						this.$api.msg(res.data.msg);
						return;
					}
					
				})
			},
			SwitchA(e) {  
				this.switchA = e.detail.value
				var obj = {
					token: uni.getStorageSync('token'),
					findtype_phone:e.detail.value?1:2
				}
				this.$common.requests('/api/User/updatefindtype_phone', obj).then(res => {
					// console.log(res)
					if(res.data.code==1){
						this.$api.msg(res.data.msg);
						return;
					}else{
						this.$api.msg(res.data.msg);
						return;
					}
					
				})
			},
			SwitchB(e) {
				this.switchB = e.detail.value
				var obj = {
					token: uni.getStorageSync('token'),
					findtype_id:e.detail.value?1:2
				}
				this.$common.requests('/api/User/updatefindtype_id', obj).then(res => {
					if(res.data.code==1){
						this.$api.msg(res.data.msg);
						return;
					}else{
						this.$api.msg(res.data.msg);
						return;
					}
					
				})
			},
			//群聊添加
			SwitchC(e) {
				this.switchC = e.detail.value
				var obj = {
					token: uni.getStorageSync('token'),
					addtype_group:e.detail.value?1:2
				}
				this.$common.requests('/api/User/updateaddtype_group', obj).then(res => {
					// console.log(res)
					if(res.data.code==1){
						this.$api.msg(res.data.msg);
						return;
					}else{
						this.$api.msg(res.data.msg);
						return;
					}
					
				})
			},
			//二维码
			SwitchD(e) {
				this.switchD = e.detail.value
				var obj = {
					token: uni.getStorageSync('token'),
					addtype_code:e.detail.value?1:2
				}
				this.$common.requests('/api/User/updateaddtype_code', obj).then(res => {
					// console.log(res)
					if(res.data.code==1){
						this.$api.msg(res.data.msg);
						return;
					}else{
						this.$api.msg(res.data.msg);
						return;
					}
					
				})
			},
			//名片
			SwitchE(e) {
				this.switchE = e.detail.value
				var obj = {
					token: uni.getStorageSync('token'),
					addtype_ming:e.detail.value?1:2
				}
				this.$common.requests('/api/User/updateaddtype_ming', obj).then(res => {
					// console.log(res)
					if(res.data.code==1){
						this.$api.msg(res.data.msg);
						return;
					}else{
						this.$api.msg(res.data.msg);
						return;
					}
					
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
		background: $uni-color-bei;
	}
	.titles{
		padding: 24upx 0 24upx 24upx;
	}
	.content{
		height: 100%;
	}
	.uni-switch-input .uni-switch-input-checked{
		    background-color: rgb(0, 122, 255)!important;
	} 
</style>
